package org.example.struct.array2;

import java.util.HashMap;
import java.util.Map;

/**
 * @author liyishan
 * @date 2024/5/11 10:02
 * @apiNote
 */

public class Test02391GarbageCollection {

    public int garbageCollection(String[] garbage, int[] travel) {
        Map<Character, Integer> dis = new HashMap<>();
        int res = 0, curDis = 0;
        for (int i = 0; i < garbage.length; i++) {
            res += garbage[i].length();
            if (i > 0) {
                curDis += travel[i - 1];
            }
            for (char c : garbage[i].toCharArray()) {
                dis.put(c, curDis);
            }
        }
        return res + dis.values().stream().reduce(0, Integer::sum);
    }
}
